package acceptTests;

import java.io.IOException;

import exceptions.database.InvalidUserListException;
import sessionManager.SessionManager;
import sessionManager.SessionManagerIF;
import user.UserIF;
import user.blog.BlogIF;

public class US05Facade {

	private SessionManagerIF session;

	public US05Facade() {
		session = SessionManager.getInstance();
	}

	public void cleanPersistence() {
		session.cleanPersistence();
	}

	public void createProfile(String login, String senha, String nome_exibicao,
			String email, String sexo, String dataNasc, String endereco,
			String interesses, String quem_sou_eu, String filmes,
			String musicas, String livros) throws Exception {
		session.createUser(login, senha, nome_exibicao, email, sexo, dataNasc,
				endereco, interesses, quem_sou_eu, filmes, musicas, livros);
	}

	public String createBlog(String idSession, String titulo, String descricao)
			throws Exception {
		return session.getUser(idSession).createBlog(idSession, titulo,
				descricao);
	}

	public String getBlogInformation(String id, String atributo) {
		for (UserIF user : session.getUsers()) {
			for (BlogIF blog : user.getBlogs()) {
				if (blog.getId().equals(id)) {
					if (atributo.equals("titulo")) {
						return blog.getTitle();
					} else if (atributo.equals("descricao")) {
						return blog.getDescription();
					}
				}
			}
		}
		return "Blog inexistente!";
	}

	public void changeBlogInformation(String idSession, String id,
			String atributo, String valor) throws Exception {
		session.getUser(idSession).changeBlogInformation(idSession, id,
				atributo, valor);
	}

	public String logon(String login, String senha) throws Exception {
		return session.loginUser(login, senha);
	}

	public boolean logoff(String sessionID) throws Exception {
		return session.logoffUser(sessionID);
	}

	public void saveData() throws InvalidUserListException, IOException {
		session.saveData();
	}
}